﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text.RegularExpressions;

namespace wdss.WebServices
{
    public class EmailSyntax
    {
        public Boolean VerifyEmail(String EmailId)
        {
            int count = 0;
            char[] chars = EmailId.ToCharArray();

            String strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
                 @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
                 @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";

            Regex re = new Regex(strRegex);



            int FirstAtIndex = EmailId.IndexOf('@');
            int LastIndex = EmailId.LastIndexOf('@');

            foreach (char c in chars)
            {
                if (c == '@')
                {
                    count++;
                }
            }

            if (EmailId.Length > 8)
            {
                if (EmailId.Contains("@") && count < 2 && FirstAtIndex == LastIndex

                     && EmailId.Contains(".") && re.IsMatch(EmailId))
                {
                    return true;
                }

                else
                {
                    return false;
                }
            }


            return false;
        }
    }
}
